/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Admin;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import dao.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;
import pojo.*;
/**
 *
 * @author Dang Nhung
 */
public class Admin_ShowtimesManage extends javax.swing.JPanel {

    private DefaultTableModel model1 = null;
    List<Suatchieu> suatChieus = null;
    private String arr_trash[] = {"Không hoạt động","Hoạt động"};
    
      /**
     * Declare string constant
     */
    private final String ERR_LIST_EMPTY = "Show time list is empty";
    private final String ERR_SELECTED_SHOWTIME_EMPTY = "Selected show time is empty";
    private final String LABEL_SAVE = "Save";
    private final String LABEL_UPDATE = "Update Showtime";
    private final String LABEL_ADD = "Add Showtime";
    private final String LABEL_EMPTY = "";
    
    /*
     * Clean Jtextfield and selection
     */
    private void clearTextFields() {
        this.jtxtcodeid.setText(LABEL_EMPTY);
        this.jtxtstarttime.setText(LABEL_EMPTY);
        this.jtxtendtime.setText(LABEL_EMPTY);
        this.jcbroomstate2.setSelectedIndex(1);
        this.jtblistofroom.clearSelection();
    }
    
    /**
     * Init state of components
     */
    private void initStateComponents() {
        // Disable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtstarttime.setEnabled(false);
        this.jtxtendtime.setEnabled(false);
        this.jcbroomstate2.setEnabled(false);
        // Disable all button except Add room button
        this.jbtnreset3.setEnabled(false);
        this.jbtnaddshowtime.setEnabled(true);
        this.jbtnupdateshowtime.setEnabled(false);
        this.jbtndeleteshowtime.setEnabled(false);
        this.jbtncancel3.setEnabled(false);
        // Set text all
        jbtnaddshowtime.setText(LABEL_ADD);
        jbtnupdateshowtime.setText(LABEL_UPDATE);
        // Remove selected row
        this.jtblistofroom.clearSelection();
    }
    
     /**
     * selected state of components while selected row in jTable
     */
    private void selectedStateComponents() {
        // Disable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtstarttime.setEnabled(false);
        this.jtxtendtime.setEnabled(false);
        this.jcbroomstate2.setEnabled(false);

        // Enable all button except Add room button
        this.jbtnreset3.setEnabled(true);
        this.jbtnaddshowtime.setEnabled(true);
        this.jbtnupdateshowtime.setEnabled(true);
        this.jbtndeleteshowtime.setEnabled(true);
        this.jbtncancel3.setEnabled(true);
    }
    
     /**
     * update state of components while click update button
     */
    private void updateStateComponents() {
        // Enable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtstarttime.setEnabled(true);
        this.jtxtendtime.setEnabled(true);
        this.jcbroomstate2.setEnabled(true);

        // Enable all button except Add room button
        this.jbtnreset3.setEnabled(true);
        this.jbtnaddshowtime.setEnabled(false);
        this.jbtnupdateshowtime.setEnabled(true);
        this.jbtndeleteshowtime.setEnabled(false);
        this.jbtncancel3.setEnabled(true);

        // Change label of update button to save
        this.jbtnupdateshowtime.setText(LABEL_SAVE);
    }

      /**
     * Successfully update state of components while update finished
     */
    private void updateSuccessStateComponents() {
        // Rollback init state
        initStateComponents();

        // Change label of update button to update
        this.jbtnupdateshowtime.setText(LABEL_UPDATE);
    }
    
     /**
     * Add state of components while add finished
     */
    private void addStateComponents() {
        // Enable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtstarttime.setEnabled(true);
        this.jtxtendtime.setEnabled(true);
        this.jcbroomstate2.setEnabled(true);

        // Enable all button except Add room button
        this.jbtnreset3.setEnabled(true);
        this.jbtnaddshowtime.setEnabled(true);
        this.jbtnupdateshowtime.setEnabled(false);
        this.jbtndeleteshowtime.setEnabled(false);
        this.jbtncancel3.setEnabled(true);

        // Flush text
        clearTextFields();

        // Change label of update button to save
        this.jbtnaddshowtime.setText(LABEL_SAVE);
    }
    
      private void addSuccessStateComponents() {
        // Rollback init state
        initStateComponents();

        // Change label of update button to Save
        this.jbtnaddshowtime.setText(LABEL_SAVE);
    }
    /**
     * Creates new form Admin_ShowtimesManage
     */
    public Admin_ShowtimesManage() {
        initComponents();
        initStateComponents();
        LoadDBJTable();
    }
    final public void LoadDBJTable(){
        model1 = (DefaultTableModel)jtblistofroom.getModel();
        model1.getDataVector().clear();
        try{
             suatChieus = SuatChieuDAO.getSuatChieus();
             int count = 0;
             for(Suatchieu suatchieu : suatChieus){
                 Vector v =new Vector();
                 count = count + 1;
                 v.addElement(count);
                 v.addElement(suatchieu.getCodeSuatChieu());
                 v.addElement(suatchieu.getGioBatDau());
                 v.addElement(suatchieu.getGioKetThuc());
                 v.addElement(arr_trash[suatchieu.getTrangThai()]);
                 model1.addRow(v);
             }
             jtblistofroom.setModel(model1);
        }catch(Exception ex){
            ex.printStackTrace();
        }
       
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDayChooser1 = new com.toedter.calendar.JDayChooser();
        jPanel1 = new javax.swing.JPanel();
        jlbselectcodeid = new javax.swing.JLabel();
        jbtnok = new javax.swing.JButton();
        jbtnshowall = new javax.swing.JButton();
        jcbselectcodeid = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jlbcodeid = new javax.swing.JLabel();
        jtxtcodeid = new javax.swing.JTextField();
        jtxtstarttime = new javax.swing.JTextField();
        jlbstarttime = new javax.swing.JLabel();
        jlbendtime = new javax.swing.JLabel();
        jtxtendtime = new javax.swing.JTextField();
        jcbroomstate2 = new javax.swing.JComboBox();
        jlbstateofshowtime = new javax.swing.JLabel();
        jbtnreset3 = new javax.swing.JButton();
        jbtnaddshowtime = new javax.swing.JButton();
        jbtnupdateshowtime = new javax.swing.JButton();
        jbtndeleteshowtime = new javax.swing.JButton();
        jbtncancel3 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jlblistofshowtimes = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblistofroom = new javax.swing.JTable();

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setFont(new java.awt.Font("Tahoma", 1, 11));

        jlbselectcodeid.setFont(new java.awt.Font("Tahoma", 3, 12));
        jlbselectcodeid.setText("Select Code ID");

        jbtnok.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtnok.setText("OK");

        jbtnshowall.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtnshowall.setText("Show All");

        jcbselectcodeid.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbselectcodeid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbselectcodeidActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jlbselectcodeid, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jcbselectcodeid, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jbtnok, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnshowall)
                .addContainerGap(53, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbselectcodeid)
                    .addComponent(jcbselectcodeid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnok)
                    .addComponent(jbtnshowall))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlbcodeid.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbcodeid.setText("Code ID");

        jlbstarttime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbstarttime.setText("Start Time");

        jlbendtime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbendtime.setText("End Time");

        jcbroomstate2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Không hoạt động", "Hoạt động" }));

        jlbstateofshowtime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlbstateofshowtime.setText("State of Showtime");

        jbtnreset3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtnreset3.setText("Reset");
        jbtnreset3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnreset3ActionPerformed(evt);
            }
        });

        jbtnaddshowtime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtnaddshowtime.setText("Add Showtime");
        jbtnaddshowtime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnaddshowtimeActionPerformed(evt);
            }
        });

        jbtnupdateshowtime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtnupdateshowtime.setText("Update Showtime");
        jbtnupdateshowtime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnupdateshowtimeActionPerformed(evt);
            }
        });

        jbtndeleteshowtime.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtndeleteshowtime.setText("Delete Showtime");
        jbtndeleteshowtime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtndeleteshowtimeActionPerformed(evt);
            }
        });

        jbtncancel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jbtncancel3.setText("Cancel");
        jbtncancel3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtncancel3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jbtnreset3, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnaddshowtime)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnupdateshowtime)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtndeleteshowtime)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtncancel3, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlbstarttime)
                            .addComponent(jlbstateofshowtime)
                            .addComponent(jlbcodeid)
                            .addComponent(jlbendtime))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtcodeid, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtxtstarttime, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jcbroomstate2, 0, 353, Short.MAX_VALUE)
                            .addComponent(jtxtendtime))))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbcodeid)
                    .addComponent(jtxtcodeid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbstarttime)
                    .addComponent(jtxtstarttime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbendtime)
                    .addComponent(jtxtendtime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbroomstate2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbstateofshowtime))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jbtncancel3)
                    .addComponent(jbtndeleteshowtime)
                    .addComponent(jbtnupdateshowtime)
                    .addComponent(jbtnreset3)
                    .addComponent(jbtnaddshowtime))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlblistofshowtimes.setFont(new java.awt.Font("Tahoma", 1, 18));
        jlblistofshowtimes.setText("List Of Showtimes");

        jtblistofroom.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "STT", "Code ID", "Start Time ", "End Time", "Showtime's State"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jtblistofroom.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblistofroomMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtblistofroom);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jlblistofshowtimes)
                        .addGap(0, 579, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlblistofshowtimes, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(276, 276, 276))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(514, 514, 514))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jcbselectcodeidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbselectcodeidActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbselectcodeidActionPerformed

    private void jbtndeleteshowtimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtndeleteshowtimeActionPerformed
        // TODO add your handling code here:
         try{
            int selectRow = jtblistofroom.getSelectedRow();
            Suatchieu lp = suatChieus.get(selectRow);
            lp.setTrangThai(0);
            boolean kq = SuatChieuDAO.updateSuatChieus(lp);
            if (kq == true){
                LoadDBJTable();
            }
            clearTextFields();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtndeleteshowtimeActionPerformed

    private void jbtnreset3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnreset3ActionPerformed
        // TODO add your handling code here:
         initStateComponents();
         clearTextFields();
    }//GEN-LAST:event_jbtnreset3ActionPerformed

    private void jbtncancel3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtncancel3ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jbtncancel3ActionPerformed

    private void jtblistofroomMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblistofroomMouseClicked
        // TODO add your handling code here:
        try{
            if(suatChieus == null){
                throw new  Exception(ERR_LIST_EMPTY);
            }
            int selectRow = jtblistofroom.getSelectedRow();
            Suatchieu sc = suatChieus.get(selectRow);
            if (sc == null) {
                throw new Exception(ERR_SELECTED_SHOWTIME_EMPTY);
            }
            selectedStateComponents();
            this.jtxtcodeid.setText(sc.getCodeSuatChieu().toString());
            this.jtxtstarttime.setText(sc.getGioBatDau().toString());
            this.jtxtendtime.setText(sc.getGioKetThuc().toString());
            this.jcbroomstate2.setSelectedIndex(sc.getTrangThai());
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jtblistofroomMouseClicked

    private void jbtnaddshowtimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnaddshowtimeActionPerformed
        // TODO add your handling code here:
        try{
           String rollAction = this.jbtnaddshowtime.getText();
           if (rollAction.compareToIgnoreCase(LABEL_SAVE) == 0) {
               Suatchieu sc = new Suatchieu();
               List<Suatchieu> list = SuatChieuDAO.getAllSuatChieus();
               if(list.size()>0){
                   String temp = "SuatChieu" + ((list.get(list.size()-1).getIdSuatChieu())+1);
                   if(jtxtstarttime.getText().equals("") || jtxtendtime.getText().equals("")){
                        JOptionPane.showMessageDialog(null,"Start time and end time aren't empty");
                        this.jbtnaddshowtime.setText(LABEL_SAVE);
                   }
                   else{
                       sc.setIdSuatChieu((list.get(list.size()-1).getIdSuatChieu())+1);
                       sc.setCodeSuatChieu(temp);
                       DateFormat formatter;
                       DateFormat df=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
                       Date gbd,gkt;
                       gbd=(Date)df.parse(jtxtstarttime.getText());
                       gkt=(Date)df.parse(jtxtendtime.getText());
                       sc.setGioBatDau(gbd);
                       sc.setGioKetThuc(gkt);
                       sc.setTrangThai(jcbroomstate2.getSelectedIndex());
                       boolean kq = SuatChieuDAO.insertSuatChieus(sc);
                       LoadDBJTable();
                       clearTextFields();
                       addSuccessStateComponents();
                   }
               }
           }
           else{
               addStateComponents();
           }
            // If update button is saving state
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtnaddshowtimeActionPerformed

    private void jbtnupdateshowtimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnupdateshowtimeActionPerformed
        // TODO add your handling code here:
        try{
            String rollAction= this.jbtnupdateshowtime.getText();
            //If update button is saving state
            if(rollAction.compareToIgnoreCase(LABEL_SAVE)==0)
            {
                Suatchieu sc= new Suatchieu();
                int selectedRow= jtblistofroom.getSelectedRow();
                sc.setIdSuatChieu(suatChieus.get(selectedRow).getIdSuatChieu());
                sc.setCodeSuatChieu(jtxtcodeid.getText());
                DateFormat df=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
                Date gbd,gkt;
                gbd=(Date)df.parse(jtxtstarttime.getText());
                gkt=(Date)df.parse(jtxtendtime.getText());
                sc.setGioBatDau(gbd);
                sc.setGioKetThuc(gkt);
                sc.setTrangThai(jcbroomstate2.getSelectedIndex());
                if(this.jtxtstarttime.getText().equals("")|| this.jtxtendtime.getText().equals("")){
                    JOptionPane.showMessageDialog(null,"Start time and end time aren't empty");
                    this.jbtnupdateshowtime.setText(LABEL_SAVE);
                }
                else{
                    boolean kq=SuatChieuDAO.updateSuatChieus(sc);
                    LoadDBJTable();
                    updateSuccessStateComponents();
                    clearTextFields();
                }
            }
            else{
              updateStateComponents();
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtnupdateshowtimeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDayChooser jDayChooser1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnaddshowtime;
    private javax.swing.JButton jbtncancel3;
    private javax.swing.JButton jbtndeleteshowtime;
    private javax.swing.JButton jbtnok;
    private javax.swing.JButton jbtnreset3;
    private javax.swing.JButton jbtnshowall;
    private javax.swing.JButton jbtnupdateshowtime;
    private javax.swing.JComboBox jcbroomstate2;
    private javax.swing.JComboBox jcbselectcodeid;
    private javax.swing.JLabel jlbcodeid;
    private javax.swing.JLabel jlbendtime;
    private javax.swing.JLabel jlblistofshowtimes;
    private javax.swing.JLabel jlbselectcodeid;
    private javax.swing.JLabel jlbstarttime;
    private javax.swing.JLabel jlbstateofshowtime;
    private javax.swing.JTable jtblistofroom;
    private javax.swing.JTextField jtxtcodeid;
    private javax.swing.JTextField jtxtendtime;
    private javax.swing.JTextField jtxtstarttime;
    // End of variables declaration//GEN-END:variables
}
